/*
package com.mediacloud.app.newsmodule.view;

import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.*;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mediacloud.app.model.interfaces.DataInvokeCallBack;
import com.mediacloud.app.model.news.ArticleItem;
import com.mediacloud.app.model.news.BaseMessageReciver;
import com.mediacloud.app.user.model.UserInfo;
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.utils.Addintegral;
import com.mediacloud.app.newsmodule.utils.CommentPublishInvoker;
import com.mediacloud.app.newsmodule.utils.ToastUtil;
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig;
import com.mediacloud.app.reslib.util.ModuleReferenceConfig;
import com.mediacloud.app.reslib.view.SimpleDialog;

public class CommentDialogFram extends PopupWindow {

    public TextView writeComment;
    public View cancelComment;
    public EditText commentInputText;
    public ArticleItem articleItem;
    public RelativeLayout topLayout;
    public CommentPublishInvoker commentPublishInvoker;
    SubmitCommentCallBack callBack;
    public SubmitCommentListener commentListener;
    public SimpleDialog simpleDialog;
    protected Context mContext;
    String VIEW_LOG_TAG = "test";
    View mView;
    TextView tx_paste;
    LinearLayout copyandpaste;
    private ClipboardManager mClipboard = null;
    public CommentDialogFram(Context context) {
        super(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
//        setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        mContext = context;
        setBackgroundDrawable(new BitmapDrawable());
        setOutsideTouchable(true);
        setFocusable(true);
        mView = LayoutInflater.from(mContext).inflate(R.layout.aappfactory_layout_comment_input, null);
        setContentView(mView);
        setAnonymousView();
        initChild(mContext);
        commentInputText.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Log.i("test","EditTextView:onlong"+v.getId());
                copyandpaste.setVisibility(View.VISIBLE);
                return false;
            }
        });
        mClipboard = (ClipboardManager)mContext. getSystemService(Context.CLIPBOARD_SERVICE);
    }

//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container,
//                             Bundle savedInstanceState) {
//        System.out.println("tag = " + getTag());
//        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
//
//        mContext = getActivity();
//        if (mView == null) {
//            mView = inflater.inflate(R.layout.aappfactory_layout_comment_input, null);
//            initChild(getActivity());
//        }
//        return mView;
//    }

//    @Override
//    public void onStart() {
//        super.onStart();
//        DisplayMetrics dm = new DisplayMetrics();
//        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
//        getDialog().getWindow().setLayout(dm.widthPixels, getDialog().getWindow().getAttributes().height);
//        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0x5f000000));
//        Window window = getDialog().getWindow();
//        WindowManager.LayoutParams lp = window.getAttributes();
//        lp.gravity = Gravity.BOTTOM; // 紧贴底部
//        lp.width = WindowManager.LayoutParams.MATCH_PARENT; // 宽度持平
//        window.setAttributes(lp);
//    }

    private void pasteToResult() {
        // Gets a handle to the clipboard service.
        String resultString = "";
        // 检查剪贴板是否有内容
        if (mClipboard.hasPrimaryClip())
        {
//            com.utils.ToastUtil.showToastCenter(mContext,
//                    "Clipboard is empty", Toast.LENGTH_SHORT);
            ClipData clipData = mClipboard.getPrimaryClip();
            int count = clipData.getItemCount();
            for (int i = 0; i < count; ++i) {
                ClipData.Item item = clipData.getItemAt(i);
                CharSequence str = item
                        .coerceToText(mContext);
                Log.i("mengdd", "item : " + i + ": " + str);
                resultString += str;
            }
        }
        commentInputText.append(resultString);
        commentInputText.setSelection(commentInputText.getText().length());
    }

    protected void initChild(final Context context) {
        simpleDialog = new SimpleDialog(context);
        callBack = new SubmitCommentCallBack();
        commentPublishInvoker = new CommentPublishInvoker(callBack);
        topLayout = (RelativeLayout) mView.findViewById(R.id.topLayout);
        tx_paste=(TextView) mView.findViewById(R.id.tx_paste);
        copyandpaste=(LinearLayout) mView.findViewById(R.id.copyandpaste);
        copyandpaste.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                copyandpaste.setVisibility(View.GONE);
                pasteToResult();
            }
        });

        writeComment = (TextView) mView.findViewById(R.id.writeComment);
        cancelComment = mView.findViewById(R.id.cancelComment);
        commentInputText = (EditText) mView.findViewById(R.id.commentInputText);
        float size = mContext.getResources().getDimensionPixelSize(R.dimen.dime_fifteendp);
        commentInputText.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
        commentInputText.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                                      int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {
                copyandpaste.setVisibility(View.GONE);
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (commentInputText.getText().length() > 0) {
                    writeComment.setTextColor(AppFactoryGlobalConfig
                            .getAppServerConfigInfo(mContext).getMainColor());
                } else {
                    writeComment.setTextColor(0x999999);
                }
                copyandpaste.setVisibility(View.GONE);
            }
        });
        commentInputText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {

                }
            }
        });
        writeComment.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (commentInputText.getText().length() == 0) {
                    ToastUtil.show(context, R.string.comment_cantnull);
                    return;
                }
                UserInfo info = UserInfo.getUserInfo(context);
                if (info.isLogin()) {
                    simpleDialog.show();
                    simpleDialog.updateText(R.string.comment_submit);
                    // String nickName=info.getNickname();
                    String uid = info.getUserid();
                    // if(TextUtils.isEmpty(nickName))
                    // nickName=getResources().getString(R.string.anonymous_commentname);
                    commentPublishInvoker.publishComment(
                            info.getAvatar(),
                            info.getNickname(),
                            String.valueOf(articleItem.getId()), uid,
                            commentInputText.getText().toString(),
                            mous,
                            context
                    );
                } else {
                    intoLogin(context);
                }
            }
        });

        cancelComment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hide();
            }
        });

//        Dialog dialog = getDialog();
//        dialog.setOnShowListener(new DialogInterface.OnShowListener(){
//            @Override
//            public void onShow(DialogInterface dialog) {
//                show();
//            }
//        });
    }

    */
/**
     * 匿名和共享地理位置相关
     *//*

    public CheckBox anonymousCheckBox;
    public int mous = 0;

    protected void setAnonymousView() {
        anonymousCheckBox = (CheckBox) mView.findViewById(R.id.anonymousCheckBox);
        if (mContext.getResources().getString(R.string.needAnonymous).equals("0"))
            anonymousCheckBox.setVisibility(View.GONE);
        anonymousCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(compoundButton.isChecked()){
                    anonymousCheckBox.setTextColor(mContext.getResources().getColor(R.color.mousColor));
                    mous = 1;
                }else{
                    mous = 0;
                    anonymousCheckBox.setTextColor(mContext.getResources().getColor(R.color.color_999));
                }
            }
        });

    }


    public interface SubmitCommentListener {
        public void success();

        public void failed();
    }

    protected void intoLogin(Context context) {
        ToastUtil.show(context, R.string.please_login);
        Intent intent = new Intent();
        intent.setClassName(context, ModuleReferenceConfig.LoginActivity);
        context.startActivity(intent);
    }

    class SubmitCommentCallBack implements
            DataInvokeCallBack<BaseMessageReciver> {

        @Override
        public void success(BaseMessageReciver data) {
            simpleDialog.dismiss();
            if (data.state) {
                commentInputText.getText().clear();
                ToastUtil.show(mContext, R.string.comment_success);
                Addintegral.addintegral(mContext, 3);
                if (commentListener != null)
                    commentListener.success();
            } else {
                fault(null);
            }
            Log.w(VIEW_LOG_TAG, "success" + data);
            dismiss();
        }

        @Override
        public void fault(Object data) {
            Log.w(VIEW_LOG_TAG, "fault" + data);
            ToastUtil.show(mContext, R.string.comment_failed);
            if (commentListener != null)
                commentListener.failed();
            simpleDialog.dismiss();
        }

    }

    public void show(View container) {

        dismiss();
        copyandpaste.setVisibility(View.GONE);
        showAtLocation(container, Gravity.BOTTOM, 0, 0);// heightPixels-contentView.getHeight());
        commentInputText.setFocusable(true);
        commentInputText.setFocusableInTouchMode(true);
        commentInputText.requestFocus();
        InputMethodManager imm = (InputMethodManager) writeComment
                .getContext().getSystemService(
                        Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(500, InputMethodManager.HIDE_NOT_ALWAYS);

    }

    public void hide() {
        this.dismiss();
    }

    @Override
    public void dismiss() {
        InputMethodManager inputmanger = (InputMethodManager) writeComment
                .getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        inputmanger.hideSoftInputFromWindow(commentInputText.getWindowToken(),
                0);
        super.dismiss();
    }

    public void destory() {
        if (simpleDialog != null)
            simpleDialog.dismiss();
        simpleDialog = null;
        commentListener = null;
        if (commentPublishInvoker != null)
            commentPublishInvoker.destory();
        commentPublishInvoker = null;
    }

}
*/